﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using NetMQ;
using NetMQ.Sockets;
namespace Lawn.NetMessager
{
    using NetMQ;
    using NetMQ.Sockets;
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;

    namespace WinMessageRec
    {
        public class MessageSender : IDisposable
        {



            public int Port { get; set; }


            private PublisherSocket publisherSocket;

            public MessageSender()
            {


            }
            public MessageSender(int port) : this()
            {


                this.Port = port;
                this.publisherSocket = new PublisherSocket();
                this.publisherSocket.Bind($"tcp://*:{Port}");


            }


            public void Close()
            {

                this.publisherSocket.Close();
                NetMQConfig.Cleanup();
            }

            public void SendMessage(string topic, byte[] message)
            {

                this.publisherSocket.SendMoreFrame(topic).TrySendFrame(message);

            }

            public void Dispose()
            {
                this.Close();
            }
        }
    }

}
